package com.windy.search.listener;

import com.windy.app.entity.Product;
import com.windy.app.vo.Result;
import com.windy.search.service.SearchService;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(consumerGroup = "app-product-producter",
        topic = "product-2-es",selectorExpression = "product-2-es-tag",
        consumeMode = ConsumeMode.CONCURRENTLY,//消费模式为集群模式，一个消息只允许消费一次
        messageModel = MessageModel.CLUSTERING//消费信息顺序为无序
        )
public class ConsumerListener implements RocketMQListener<Product> {

    @Autowired
    private SearchService searchService;

    @Override
    public void onMessage(Product product) {
        System.out.println(product.toString());
        product.setId(3L);
        Result result = searchService.product2es(product);
        System.out.println(result.toString());
    }
}
